package com.jjb.spider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import java.lang.reflect.Array;
import java.time.Duration;

@SpringBootApplication
public class SpiderApplication {


    public static void main(String[] args) throws InterruptedException {
        //SpringApplication.run(SpiderApplication.class, args);
        Scheduler scheduler = Schedulers.newBoundedElastic(10,3,"线程");
        Integer[] a = new Integer[2000];
        for (int i = 0; i < a.length; i++) {
            a[i]=i;
            Mono.just(i)

                    .publishOn(scheduler)
                    .subscribe(z -> {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        System.out.println("subscribe: "+z+"  " + Thread.currentThread().getName());
                    });

        }
//        Flux.just(a)
//                .map(i ->{
//                    System.out.println("map1: " + Thread.currentThread().getName());
//
//                    return i;
//                })
//                .publishOn(Schedulers.newBoundedElastic(10,100000,"线程名")) //指定在parallel线程池中执行
//                //.publishOn(Schedulers.elastic()) // 指定下游的执行线程
//
//                .map(i ->{
//                    try {
//                        Thread.sleep(1000);
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                    System.out.println("map2: " + Thread.currentThread().getName());
//                    return i;
//                 })
//                //.subscribeOn(Schedulers.single())
//                .subscribe(i -> System.out.println("subscribe: " + Thread.currentThread().getName()));



        System.out.println(Thread.currentThread().getName());
        Thread.sleep(1000000);
    }

}